{extend name="../admin/common/base" /}
{block name="nav_title"}
    <div class="layui-row">
        <div class="layui-col-md10">
            <form class="layui-form" action="">
                <div class="layui-col-md2">
                    <div class="layui-form-item">
                        <select name="search_type" lay-filter="types" lay-verify="required">
                            <option {if $search_type==1} selected {/if} value="1">全部</option>
                            <option {if $search_type==2} selected {/if} value="2">当前类型</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-md5" style="margin-left: 5px; line-height: 38px;">
                    <div class="layui-form-item">
                        <input name="keyword" placeholder="请输入关键词" value="{:input('keyword')}" class="layui-input" type="text">
                    </div>
                </div>
                <div class="layui-col-md4" style="margin-left: 5px; line-height: 38px;">
                    <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="formDemo">搜索内容</button>
                </div>
            </form>
        </div>
        <div class="layui-col-md2">
            <a href="{:url('addKeyword')}" id="addkw" class="layui-btn layui-btn-normal layui-btn-sm" style="float: right;margin-top: 5px;">增加关键词</a>
        </div>
    </div>
{/block}
{block name="body"}
{include file="/common/autoreplay_nav" /}
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li {eq name="type" value="text"}class="layui-this"{/eq} ><a href="{:url('mp/Mp/autoReply',['type'=>'text'])}">回复文字</a></li>
        <li {eq name="type" value="news"}class="layui-this"{/eq}><a href="{:url('mp/Mp/autoReply',['type'=>'news'])}">回复图文</a></li>
        <li {eq name="type" value="addon"}class="layui-this"{/eq}><a href="{:url('mp/Mp/autoReply',['type'=>'addon'])}">回复应用</a></li>
        <li {eq name="type" value="voice"}class="layui-this"{/eq}><a href="{:url('mp/Mp/autoReply',['type'=>'voice'])}">回复语音</a></li>
        <li {eq name="type" value="image"}class="layui-this"{/eq}><a href="{:url('mp/Mp/autoReply',['type'=>'image'])}">回复图片</a></li>
        <li {eq name="type" value="video"}class="layui-this"{/eq}><a href="{:url('mp/Mp/autoReply',['type'=>'video'])}">回复视频</a></li>
        <li {eq name="type" value="music"}class="layui-this"{/eq}><a href="{:url('mp/Mp/autoReply',['type'=>'music'])}">回复音乐</a></li>
        {if input('keyword')}
        <li {eq name="type" value="search"}class="layui-this"{/eq}><a>搜索全部</a></li>
        {/if}
    </ul>
    <div class="layui-tab-content">

        {switch name="type"}
            {case value="text"}
        <table class="layui-table" lay-skin="line">
            <colgroup>
                <col width="120">
                <col >
                <col width="100" >
                <col width="150">
            </colgroup>
                    <thead>
                    <tr>
                        <th>关键词</th>
                        <th>回复内容</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="data" id="vo"}
                    <tr>
                        <td>{$vo.keyword}</td>
                        <td>{$vo.content}</td>
                        <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                        <td>
                            <div class="">
                                <a class="rha-bt-a" href="javascript:;" onclick="editReply('{$vo.id}')">修改</a>
                                {if condition="$vo.status=='1'"}
                                <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                                {else/}
                                <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                                {/if}
                                <a class="rha-bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>
                            </div>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            {$data->render()|raw}
            {/case}
            {case value="news"}
                <table class="layui-table" lay-skin="line">
                    <col width="120">
                    <col width="200">
                    <col width="150">
                    <col width="">
                    <col width="100" >
                    <col width="150">
                    <thead>
                    <tr>
                        <th>关键词</th>
                        <th>标题</th>
                        <th>封面图</th>
                        <th>图文描述</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="data" id="vo"}
                    <tr>
                        <td>{$vo.keyword}</td>
                        <td>{$vo.title}</td>
                        <td>
                            <div  style="padding: 1px; border: #e6e6e6 solid 1px; width:120px; float: left; ">
                            <img class="form_logo" src="{$vo.url}" style="max-width: none" width="120" height="60">
                            </div>
                        </td>
                        <td>{$vo.content}</td>
                        <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                        <td>
                            <div class="">
                                <a class="rha-bt-a" href="javascript:;" onclick="editReply('{$vo.id}')">修改</a>
                                {if condition="$vo.status=='1'"}
                                <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                                {else/}
                                <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                                {/if}
                                <a class="rha-bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>

                            </div>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
        {$data->render()|raw}
            {/case}
        {case value="addon"}
        <table class="layui-table" lay-skin="line">
            <col width="120">
            <col width="200">
            <col width="" >
            <col width="100">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>应用名称</th>
                <th>应用简介</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>
                    <div  style=" float: left; ">
                        <img class="form_logo" src="{$vo.logo}" width="30" height="30">{$vo.name}
                    </div>
                    </td>
                <td>{$vo.desc}</td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <a class="rha-bt-a" href="javascript:;" onclick="editReply('{$vo.id}')">修改</a>
                    {if condition="$vo.status=='1'"}
                    <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                    {else/}
                    <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                    {/if}
                    <a class="rha-bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>

                </td>
            </tr>
            {/volist}
            </tbody>
        </table>

        {/case}

        {case value="voice"}
        <table class="layui-table" lay-skin="line">
            <col width="">
            <col width="">
            <col width="" >
            <col width="100">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>语音名称</th>
                <th>语音资源|媒体ID</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{$vo.title}</td>
                <td>{$vo.url}</td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <a class="rha-bt-a" href="javascript:;" onclick="editReply('{$vo.id}')">修改</a>
                    {if condition="$vo.status=='1'"}
                    <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                    {else/}
                    <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                    {/if}
                    <a class="rha-bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>

                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {$data->render()|raw}
        {/case}
        {case value="image"}
        <table class="layui-table" lay-skin="line">
            <col width="">
            <col width="100">
            <col width="" >
            <col width="100">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>类型</th>
                <th>封面图</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{if condition="$vo.status_type eq '1'"} 永久
                    {elseif condition="$vo.status_type eq '0'"/}临时
                    {/if}</td>
                <td>
                    <div  style="padding: 1px; border: #e6e6e6 solid 1px; width:120px; float: left; ">
                        <img class="form_logo" src="{$vo.url}" style="max-width: none" width="120" height="60">
                    </div>
                </td>

                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <a class="rha-bt-a" href="javascript:;" onclick="editReply('{$vo.id}')">修改</a>
                    {if condition="$vo.status=='1'"}
                    <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                    {else/}
                    <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                    {/if}
                    <a class="rha-bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>

                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {$data->render()|raw}
        {/case}
        {case value="video"}
        <table class="layui-table" lay-skin="line">
            <col width="">
            <col width="100">
            <col width="" >
            <col width="" >
            <col width="100">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>类型</th>
                <th>视频标题|媒体ID</th>
                <th>视频地址</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{if condition="$vo.status_type eq '1'"} 永久
                    {elseif condition="$vo.status_type eq '0'"/}临时
                    {/if}</td>
                <td>
                    {$vo.title}
                </td>
                <td>
                    {$vo.url}
                </td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <a class="rha-bt-a" href="javascript:;" onclick="editReply('{$vo.id}')">修改</a>
                    {if condition="$vo.status=='1'"}
                    <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                    {else/}
                    <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                    {/if}
                    <a class="rha-bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>

                </td>

            </tr>
            {/volist}
            </tbody>
        </table>
        {$data->render()|raw}
        {/case}
        {case value="music"}
        <table class="layui-table" lay-skin="line">
            <col width="80">
            <col width="100">
            <col width="" >
            <col width="" >
            <col width="100">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>音乐标题</th>
                <th>链接地址</th>
                <th>音乐描述</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{$vo.title}</td>
                <td>
                    {$vo.url}
                </td>
                <td>{$vo.content}</td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <a class="rha-bt-a" href="javascript:;" onclick="editReply('{$vo.id}')">修改</a>
                    {if condition="$vo.status=='1'"}
                    <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                    {else/}
                    <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                    {/if}
                    <a class="rha-bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>

                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {$data->render()|raw}
        {/case}
        {case value="search"}
        <table class="layui-table" lay-skin="line">
            <colgroup>
                <col width="120">
                <col >
                <col width="100" >
                <col width="150">
            </colgroup>
            <thead>
            <tr>
                <th>关键词</th>
                <th>类型</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{:getRuleTypeName($vo.type)}</td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <div class="">
                        <a class="rha-bt-a" href="javascript:;" onclick="editReply('{$vo.id}')">修改</a>
                        {if condition="$vo.status=='1'"}
                        <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                        {else/}
                        <a class="rha-bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                        {/if}
                        <a class="rha-bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>
                    </div>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {$data->render()|raw}
        {/case}
        {/switch}
    </div>
</div>
<script>
    var layer;
    var form;
    layui.use(['layer','form'], function() {
        layer = layui.layer;
        form = layui.form;
        form.on('select(types)', function(data){
            $.post("",{search_type:data.value},function (res) {})
        });
    })
    function delReply(id) {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.confirm('你确定需要删除吗？', {
                btn: ['是','不'] //按钮
            }, function(){
                $.post("{:url('mp/Mp/delRule')}",{'id':id},function (res) {
                    if(res.status==1){
                        layer.alert(res.msg,function (index) {
                            window.location.reload();
                            layer.close(index);
                        })

                    }else{
                        layer.alert(res.msg)
                    }
                })
            }, function(){

            });
        });

    }
    function updateReply(id,status) {
        layui.use('layer', function(){
            var layer = layui.layer;
                $.post("{:url('mp/Mp/updateRule')}",{'id':id,'status':status},function (res) {
                    if(res.status==1){
                        layer.msg(res.msg,{icon:1,time:2000},function (index) {
                            window.location.reload();

                        })

                    }else{
                        layer.alert(res.msg)
                    }
                })
        });
    }
    var layer;
    layui.use('layer', function(){
        var layer = layui.layer;
    });
    function editReply(id) {
        layer.open({
            type: 2,
            title: '修改回复内容',
            shadeClose: true,
            shade: 0.5,
            area: ['680px', '550px'],
            content: '{:url("mp/mp/editAutoreply")}?id='+id,
            cancel: function(index, layero){
                window.location.reload();
            }
        });
    }

</script>
{/block}